package com.study.talk.ui.app.group

import android.app.Application
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.study.common.ToastUtil
import com.study.talk.ui.app.base.BaseViewModel
import com.study.talk.data.model.UserInfo
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class InviteFriendViewModel @Inject constructor(application: Application) :
    BaseViewModel(application) {
    private val _friends = MutableLiveData<List<UserInfo>>()
    val friends: LiveData<List<UserInfo>> get() = _friends

    fun getFriendsNotInGroup(groupId: Int) {
        viewModelScope.launch {
            val result = friendRepository.friendNotInGroup(groupId, app.localUserId)
            if (result.isEmpty()) {
                ToastUtil.showToast(
                    app, "暂无符合要求的好友，快去多交点朋友吧..."
                )
            } else {
                _friends.postValue(result)
            }
        }
    }
}